#ifndef BASE_SYSTEM_LOG_IO_INCLUDE_IO_MMAP_OUTPUT_STRATEGY_H
#define BASE_SYSTEM_LOG_IO_INCLUDE_IO_MMAP_OUTPUT_STRATEGY_H

#include "file_output_strategy.h"

namespace Base {
namespace SystemLog {
struct MMapOutputOptions : FileOutputOptions {
    size_t mappingSize = 64 * 1024 * 1024; // 64MB
};

class MMapOutputStrategy : public FileOutputStrategy {
public:
    explicit MMapOutputStrategy(const MMapOutputOptions &options);
    ~MMapOutputStrategy() override;
    ErrCode Write(const char* data, size_t len) override;
    ErrCode Flush() override;
    ErrCode Close() override;

    std::string GetName() const override {
        return "MMapFileOutput";
    }

private:
    ErrCode OpenFile() override;
    ErrCode CloseCurrentFile() override;
    ErrCode RemapFile(size_t requiredSize);
    ErrCode DoFlush();
    
    MMapOutputOptions mmapOptions_;
    void* mappedAddress_ = nullptr;
    size_t mappedSize_ = 0;
    size_t currentOffset_ = 0;
};
} // namespace SystemLog
} // namespace Base

#endif // BASE_SYSTEM_LOG_IO_INCLUDE_IO_MMAP_OUTPUT_STRATEGY_H